<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        width: 1210px;
        margin: 200px auto;
        color: red;
        text-align: center;
        font: 600 30px/30px "simsun";
      }
    </style>
  </head>
  <body>
    <div id="time"></div>
    <script>
      function testSet() {
        const arr = ["张三", "李四", "王五", "张三"];
        const nameset = new Set(arr);
        console.log(nameset);
        const nameArr = new Array(...nameset);
        console.log(nameArr);
      }
      testSet();

      function testObject() {
        let salaries = {
          John: 100,
          Pete: 300,
          Mary: 250,
        };
        console.log(Object.keys(salaries));
        console.log(Object.values(salaries));
        const entries = Object.entries(salaries);
        let nameTop = null;
        let salaryTop = 0;
        entries.forEach(([name, salary]) => {
          if (salary > salaryTop) {
            nameTop = name;
            salaryTop = salary;
          }
        });
        console.log(nameTop);
      }
      testObject();

      const divTime = document.getElementById("time");
      const endTime = new Date("2023-10-31 20:00:00").getTime();
      const timer = setInterval(countDown, 1000);
      function countDown() {
        const remainTime = endTime - Date.now();
        if (remainTime < 0) {
          divTime.innerHTML = "离活动还有00天00小时00分00秒";
          clearInterval(timer);
          return;
        }
        let d = parseInt(remainTime / 1000 / 60 / 60 / 24);
        let h = parseInt((remainTime / 1000 / 60 / 60) % 60);
        let m = parseInt((remainTime / 1000 / 60) % 60);
        let s = parseInt((remainTime / 1000) % 60);
        d = d < 10 ? "0" + d : d;
        h = h < 10 ? "0" + h : h;
        m = m < 10 ? "0" + m : m;
        s = s < 10 ? "0" + s : s;
        divTime.innerHTML = `离活动还有${d}天${h}小时${m}分${s}秒`;
      }

      function deepCopy(source) {
        const json = JSON.stringify(source);
        console.log(json);
        return JSON.parse(json);
      }
      const obj1 = {
        name: "zhangsan",
        age: 20,
        info: {
          desc: "student",
        },
        color: ["red", "blue", "green"],
      };
      const obj2 = { ...obj1 };
      const obj3 = deepCopy(obj1);
      obj1.info.desc = "teacher";
      console.log(obj2.info.desc);
      console.log(obj3.info.desc);
    </script>
  </body>
</html>
